<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;

class Admin extends Controller
{

    /**
     * @description :[登录操作]
     * @return array|mixed
     * @throws \think\exception\DbException
     */
    public function login(){
        if(!request()->isPost()){
            return $this->fetch();
        }else{
            $postData = input('post.');
            $account = $postData['account'];
            $password = $postData['password'];
            $where = [
                'account'   =>  $account
            ];
            $admin = model('Admin')->where($where)->find();
            if(empty($admin)){
                return show(1, '该账号不存在');
            }
            if($admin['password']!=md5($password)){
                return show(1, '密码错误');
            }
            Session::set(Base::LOGIN_USER_KEY, $admin);
            return show(0, '登录成功');
        }
    }

    /**
     * @description : [退出-删除登录标识]
     * @return array
     */
    public function logout(){
        Session::delete(Base::LOGIN_USER_KEY);
        return show(0, '退出成功');
    }

}
